<?php

namespace V1\Model;


use Think\Model;

class AreaModel extends Model
{
    protected $tablePrefix = '';
    protected $tableName = 'destoon_area';

    /**
     * 根据地区id获取地区详细
     * @param $areaid
     * @return array
     */
    public function get_area_full_name_from_area_id($areaid)
    {
        $request = $this->get_area_info_from_area_id($areaid, $x);
        return array_reverse($request);
    }

    /**
     * 获取所有地区
     * @return mixed
     */
    public function get_all_area()
    {
        $request = $this->select();
        return $request;
    }

    /**
     * @param $areaid
     * @param $area_info
     * @return array
     */
    private function get_area_info_from_area_id($areaid, &$area_info)
    {
        $data = $this->where(['areaid' => $areaid])->select();
        if ($data[0]['parentid'] == 0) {
            $area_info[] = $data[0]['areaname'];
        } else {
            $area_info[] = $data[0]['areaname'];
            $this->get_area_info_from_area_id($data[0]['parentid'], $area_info);
        }
        return $area_info;
    }
}